// 表单字段类型
type FormFieldType = 'text' | 'number' | 'date' | 'select' | 'checkbox';

// 表单字段
interface FormField {
  id: string;
  label: string;
  type: FormFieldType;
  required: boolean;
  options?: string[]; // 仅适用于 select 和 checkbox 类型
}

// 表单
interface Form {
  id: string;
  name: string;
  version: number;
  fields: FormField[];
}

// 流程节点类型
type NodeType = 'start' | 'end' | 'task' | 'condition';

// 节点
interface Node {
  id: string;
  type: NodeType;
  name: string;
  properties: Record<string, any>; // 存储节点特定属性
}

// 连接线
interface Connection {
  from: string; // 起始节点ID
  to: string;   // 目标节点ID
  condition?: string; // 条件表达式
}

// 流程
interface Process {
  id: string;
  name: string;
  version: number;
  nodes: Node[];
  connections: Connection[];
  variables: Record<string, any>; // 流程变量
}

// 任务状态
type TaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed';

// 任务
interface Task {
  id: string;
  processId: string;
  nodeId: string;
  assignee: string; // 执行人
  status: TaskStatus;
  form: Form; // 关联的表单
  data: Record<string, any>; // 任务数据
  createdAt: Date;
  updatedAt: Date;
}

// 任务历史记录
interface TaskHistory {
  taskId: string;
  action: 'claimed' | 'submitted' | 'transferred';
  by: string; // 操作人
  at: Date;
  data: Record<string, any>; // 操作数据
}

// 用户角色
type UserRole = 'admin' | 'designer' | 'executor';

// 用户
interface User {
  id: string;
  username: string;
  role: UserRole;
}

// 流程实例
interface ProcessInstance {
  id: string;
  processId: string;
  status: 'active' | 'completed' | 'terminated';
  startedAt: Date;
  completedAt?: Date;
  tasks: Task[];
  variables: Record<string, any>; // 实例变量
}

// 流程启动请求
interface StartProcessRequest {
  processId: string;
  variables: Record<string, any>;
}

// 任务领取请求
interface ClaimTaskRequest {
  taskId: string;
  assignee: string;
}

// 任务提交请求
interface SubmitTaskRequest {
  taskId: string;
  data: Record<string, any>;
}

// 任务转办请求
interface TransferTaskRequest {
  taskId: string;
  newAssignee: string;
}